local skynet = require "skynet"
require "skynet.manager" 

local L_LOGGER_NAME = ".logger"
local L_LOG_DIR = "log"

 
local date = '00'
local file2 = nil
local function log( msg )  
	local date2 = os.date("%m-%d")
	if date2 ~= date or file2 == nil then
		if file2 then
			file2:close()
		end 
		date = date2
    	file2 = assert(io.open(L_LOG_DIR.."/log-"..date,"a")) 
	end  
    local time = os.date("%m-%d-%S")
    file2:write(time..'=='..msg.."\n")  
end
 

skynet.register_protocol {
	name = "text",
	id = skynet.PTYPE_TEXT,
	unpack = skynet.tostring,
	dispatch = function(_, address, msg)
		log( msg )
	end
}

skynet.start(function()
	do
		local dir = io.open(L_LOG_DIR,"r")
		if not dir then
			os.execute(string.format("mkdir %s",L_LOG_DIR))
		end
	end  
	skynet.register(L_LOGGER_NAME) 
end)

 